/**
 * Player.java
 *
 * @author Beatrice Bacelli
 * @author Luca Bedogni
 * @author Silvia Righini
 */
package unibo.lsb.logic;

import java.io.Serializable;

/**
 * This class is the holder of all the players' data (id, status and total
 * penalties), sort of a row of PlayersTable
 */
public class Player implements Serializable {
	/**
	 * The player is alive.
	 */
	public static final int ALIVE = 0;
	/**
	 * The player crashed.
	 */
	public static final int CRASHED = 1;

	PlayerId playerId;
	int status;
	int penalty;

	/**
	 * @return the penalty
	 */
	public int getPenalty() {
		return penalty;
	}

	/**
	 * Constructor
	 * 
	 * @param playerId
	 * @param status
	 * @param penalty
	 */
	public Player(PlayerId playerId, int status, int penalty) {
		super();
		this.playerId = playerId;
		this.status = status;
		this.penalty = penalty;
	}

	/**
	 * @return the id
	 */
	public PlayerId getPlayerId() {
		return playerId;
	}

	/**
	 * @param playerId
	 *            the id to set
	 */
	public void setPlayerId(PlayerId playerId) {
		this.playerId = playerId;
	}

	/**
	 * @param penality
	 *            the penalty to set
	 */
	public void setPenalty(int penality) {
		this.penalty = penality;
	}

	/**
	 * Returns true if player is marked alive
	 * 
	 * @return the status
	 */
	public int getStatus() {
		return status;
	}

	/**
	 * @return true if the player is alive, false otherwise.
	 */
	public boolean isAlive() {
		if (status == ALIVE) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @param status
	 *            the status to set
	 */
	public void setStatus(int status) {
		this.status = status;
	}

	@Override
	public String toString() {
		String separator = "|";
		return playerId.toString() + separator + status + separator + penalty;
	}

}
